package com.microservices.yucloud.appweb.service;

import com.microservices.yucloud.appweb.domain.BizOrderResponse;
import com.microservices.yucloud.appweb.domain.Orders;
import com.microservices.yucloud.appweb.domain.StateMachineRequest;
import com.microservices.yucloud.appweb.enums.BizOrderEventsEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zy
 * @date 2019-09-04 14:37
 **/
@Slf4j
@Service
public class OrderFlowService {

    @Autowired
    private OrderStateService orderStateService;

    public void createOrder(StateMachineRequest<Orders> request) {

        try {
            BizOrderResponse response = orderStateService.sendOrderStateEvent(request, BizOrderEventsEnum.CREATE);
            if (response.getCode().equals("0")) {
                Orders orders = request.getBizModel();
                orders.setState("2");
                request.setBizModel(orders);
                response = orderStateService.sendOrderStateEvent(request, BizOrderEventsEnum.COMPUTE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
